import fs from 'fs';
import path from 'path'
export default async ctx => {
  let sureUploadArr = ['xls', 'xlsx', 'xlsb', 'xlsm', 'xlst', 'doc', 'docx', 'dotx', 'pptx', 'pdf']
  let file = ctx.request.files[ctx.info.userName];
  if (sureUploadArr.some(item => item === file.name.split('.').pop())) {
    let rStream = fs.createReadStream(file.path);
    let wStream = fs.createWriteStream(path.join(__dirname, '../public/excel/' + file.name));
    rStream.pipe(wStream)
    ctx.body = { code: 1, msg: '文件上传成功', data: '/excel/' + file.name }
    return
  }
  ctx.body = { code: 0, msg: '文件格式不支持' }
}